package Tools;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Writes out information to a specified log file
 * @author jeffrey
 *
 */
public class Log {

	private static BufferedWriter out;
	
	/**
	 * Opens the writer.  This method MUST be called to properly open the log
	 * @param filename
	 */
	public static void init(String filename)
	{
		try 
		{
			out = new BufferedWriter(new FileWriter(filename));
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * Write a message to the log
	 * @param message
	 */
	public static void Write(String message)
	{
		if(out == null)
			return;
		try 
		{ 
			out.write(message+"\n"); 
		} 
		catch (IOException e) 
		{ 
			e.printStackTrace();
		} 
	}
	
	/**
	 * Close the writer.  This method MUST be called to properly save the log
	 */
	public static void Close()
	{
		try 
		{
			out.close();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
}
